//	Author:				Joe Audette
//	Created:			2004-08-15
//	Last Modified:		2010-05-23
//		
// The use and distribution terms for this software are covered by the 
// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file CPL.TXT at the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by 
// the terms of this license.
//
// You must not remove this notice, or any other, from this software.

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using mojoPortal.Business;
using mojoPortal.Web.Framework;
using mojoPortal.Web.UI;
using mojoPortal.Web;
using Resources;
using ud_Utilities;
using System.Collections;

namespace ud_Counter.UI
{
    public partial class CounterModule : SiteModuleControl
    {
        CounterConfiguration config = new CounterConfiguration();
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += new EventHandler(Page_Load);
            this.EnableViewState = false;
        }

        protected virtual void Page_Load(object sender, EventArgs e)
        {
            LoadSettings();
            PopulateLabels();
            PopulateControls();
        }

        private void PopulateControls()
        {
            DBUtilities repository = new DBUtilities();
            if (Session["counter"] == null)
            {
                Session["counter"] = 1;
                repository.UpdateCounter();
            }
            lblVisitor.Text = repository.GetCounter(config.NumberDisplay, config.UseImage, ImageSiteRoot);
        }

        protected virtual void PopulateLabels()
        {
            lblHeader.Text = config.HeaderText;
            lblFooter.Text = config.FooterText;
        }


        protected virtual void LoadSettings()
        {
            pnlContainer.ModuleId = ModuleId;
            Hashtable settings = ModuleSettings.GetModuleSettings(ModuleId);
            config = new CounterConfiguration(settings);
            pnlContainer.CssClass += " " + config.CustomCssClass;
        }

    }
}
